@echo off

echo builder 'win-x86'

if not exist "../builder/win-x86" mkdir "../builder/win-x86"

rem windres res.rc -O coff -o res.res

:: 编译核心库
echo compiling (crosslua)...
gcc lua/*.c exlib/*.c sdl/*.c^
    -O3 -m32 -s -std=gnu11 -fno-strict-aliasing -Ilua -D_M_X64 -D_M_M64 -D_M_OS_WIN -D_M_SHARED -DCROSSLUA_LIB -DLUA_USE_POPEN^
    -Iinclude -I../SDL2_2.30.8/i686-w64-mingw32/include^
    -lmingw32 -lm -lSDL2main -lSDL2 -L../SDL2_2.30.8/i686-w64-mingw32/lib^
    -mwindows^
    -fPIC -shared -o ../builder/win-x86/crosslua.dll

copy "..\SDL2_2.30.8\i686-w64-mingw32\bin\SDL2.dll" "..\builder\win-x86\SDL2.dll" /Y

gcc lua/*.c exlib/*.c sdl/*.c clmain/*.c^
    -O3 -m32 -s -std=gnu11 -fno-strict-aliasing -Ilua -D_M_X64 -D_M_M64 -D_M_OS_WIN -DLUA_USE_POPEN^
    -Iinclude -I../SDL2_2.30.8/i686-w64-mingw32/include^
    -lmingw32 -lm -lSDL2main -lSDL2 -L../SDL2_2.30.8/i686-w64-mingw32/lib^
    -mconsole^
    -o ../builder/win-x86/crosslua.exe

echo compiling (loader)...
gcc loader/*.c^
    -O3 -m32 -s -std=gnu11 -fno-strict-aliasing -Ilua -D_M_X64 -D_M_M64 -D_M_OS_WIN -DLUA_USE_POPEN^
    -Iinclude -I../SDL2_2.30.8/i686-w64-mingw32/include^
    -lmingw32 -lm -lSDL2main -lSDL2 -L../SDL2_2.30.8/i686-w64-mingw32/lib^
    -mwindows^
    -o ../builder/win-x86/loader.exe

echo compiling (lua)...
gcc lua/*.c luaexec/*.c^
    -O3 -m32 -s -std=gnu11 -fno-strict-aliasing -Ilua -D_M_X64 -D_M_M64 -D_M_OS_WIN -DLUA_USE_POPEN^
    -Iinclude -o ../builder/win-x86/lua.exe

echo compiling (luac)...
gcc lua/*.c  luac/*.c^
    -O3 -m32 -s -std=gnu11 -fno-strict-aliasing -Ilua -D_M_X64 -D_M_M64 -D_M_OS_WIN -DLUA_USE_POPEN^
    -Iinclude -o ../builder/win-x86/luac.exe

echo compiling (pack)...
gcc pack/*.c^
    -O3 -m32 -s -std=gnu11 -fno-strict-aliasing  -D_M_X64 -D_M_M64 -D_M_OS_WIN^
    -Iinclude -o ../builder/win-x86/pack.exe

echo done
